package model;

import basics.ConversaoDeBases;

public class ULA {

	
	//Operações aritméticas
	protected String soma(String op1, String op2) {
		
		long op1Long = ConversaoDeBases.binToDecSigned(op1);
		long op2Long = ConversaoDeBases.binToDecSigned(op2);
		
		return ConversaoDeBases.DecToBin(op1Long + op2Long);
	}
	
	protected String somaU(String op1, String op2) {
		
		long op1Long = ConversaoDeBases.binToDecUnsigned(op1);
		long op2Long = ConversaoDeBases.binToDecUnsigned(op2);
		
		return ConversaoDeBases.DecToBin(op1Long + op2Long);
	}

	protected String subtracao(String op1, String op2) {
		long op1Long = ConversaoDeBases.binToDecSigned(op1);
		long op2Long = ConversaoDeBases.binToDecSigned(op2);
		
		return ConversaoDeBases.DecToBin(op1Long - op2Long);
	}
	
	protected String subtracaoU(String op1, String op2) {
		long op1Long = ConversaoDeBases.binToDecUnsigned(op1);
		long op2Long = ConversaoDeBases.binToDecUnsigned(op2);
		
		return ConversaoDeBases.DecToBin(op1Long - op2Long);
	}
	
	protected String multiplicacao(String op1, String op2) {
		long op1Long = ConversaoDeBases.binToDecSigned(op1);
		long op2Long = ConversaoDeBases.binToDecSigned(op2);

		return (ConversaoDeBases.DecToBin(op1Long * op2Long));

	 }

	protected String divisao(String op1, String op2) { 
		long op1Long = ConversaoDeBases.binToDecSigned(op1);
		long op2Long = ConversaoDeBases.binToDecSigned(op2);

		return (ConversaoDeBases.DecToBin(op1Long / op2Long));
	 }

	
	
	//Operações lógicas
	protected String shiftLeft(String op1, String shamt) {
		long op1Long = ConversaoDeBases.binToDecSigned(op1);
		long shamtLong = ConversaoDeBases.binToDecSigned(shamt);
		
		return ConversaoDeBases.DecToBin(op1Long << shamtLong);
	}

	protected String shiftRight(String op1, String shamt) {
		long op1Long = ConversaoDeBases.binToDecSigned(op1);
		long shamtLong = ConversaoDeBases.binToDecSigned(shamt);
		
		return ConversaoDeBases.DecToBin(op1Long >> shamtLong);
	}

	protected String or(String op1, String op2) {
		long op1Long = ConversaoDeBases.binToDecSigned(op1);
		long op2Long = ConversaoDeBases.binToDecSigned(op2);
		
		return (ConversaoDeBases.DecToBin(op1Long | op2Long));
	}
	
	protected String xor(String op1, String op2) {
		long op1Long = ConversaoDeBases.binToDecSigned(op1);
		long op2Long = ConversaoDeBases.binToDecSigned(op2);

		return (ConversaoDeBases.DecToBin(op1Long ^ op2Long));	
	}

	
	protected String nor(String op1, String op2) {
		long op1Long = ConversaoDeBases.binToDecSigned(op1);
		long op2Long = ConversaoDeBases.binToDecSigned(op2);

		return (ConversaoDeBases.DecToBin(~(op1Long | op2Long)));	
	}

	protected String and(String op1, String op2) {
		long op1Long = ConversaoDeBases.binToDecSigned(op1);
		long op2Long = ConversaoDeBases.binToDecSigned(op2);
		
		return (ConversaoDeBases.DecToBin(op1Long & op2Long));
	}
	
	protected String menor(String op1, String op2){
		
		if (ConversaoDeBases.binToDecSigned(op1) < ConversaoDeBases.binToDecSigned(op2))
			return ConversaoDeBases.DecToBin(1);
		else
			return ConversaoDeBases.DecToBin(0);
	}
	
	protected String menorU(String op1, String op2){
		if (ConversaoDeBases.binToDecUnsigned(op1) < ConversaoDeBases.binToDecUnsigned(op2))
			return ConversaoDeBases.DecToBin(1);
		else
			return ConversaoDeBases.DecToBin(0);
	}

	//retorna um boolean, pois a UC trará se deve fazer um desvio ou não
	protected boolean igual(String op1, String op2) {
		if (ConversaoDeBases.binToDecUnsigned(op1) == ConversaoDeBases.binToDecUnsigned(op2))		
			return true;
		else
			return false;			
	}	 

}
